Help with bash shell to alter text file

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Help with bash shell to alter text file
# 1  
Old 04-20-2010
Help with bash shell to alter text file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

Quote:
Write a bash (or Bourne) script that manages a book library database.
The script allows a user to add books to the database, check in/out a book, display books, print sorted reports and delete books. The script should be menu-based with the following options:

Main Menu:
1) Edit Submenu
2) Report Submenu
3) Quit

Edit Submenu:
1) Add a book
2) Display a book
3) Checkin book
4) Checkout book
5) Delete a book
6) Return to Main Menu

Report Submenu:
1) Sort by Author
2) Sort by Title
3) Display all checked-out books
4) Return to Main Menu

Each book entry consists of a Title, Author, Status, Borrower's name, and Check Out date. The status of a book could be in or out. The check out date and borrower's name would be empty if the status of a book is in.
The book entries must be kept in a text file (called .books) in the user's home directory with the following format:

Oracle Programming:Sunderraman:in::
Database Systems:ElMasriSmilieut:12/5/99:Jones
Java Programming:KingSmilieut:10/12/99:Smith

The title of the book serves as the primary key, i.e. we cannot have two books with the same title.
The options within the Report submenu should produce a well formatted listing of the books.

Each of the sub-options in the Edit sub-menu should interact with the user as follows:
(1) Add a book: should prompt the user for the following:

Book Title:
Author:

This option should check to see if there is a book with the same title. If present, an error message should be generated otherwise the book should be added to the database.

(2) Display a book: should prompt the user for the book title:

Book Title:

After reading the book title, this option should verify if the book exists in the database; if not, an error message should be generated; otherwise the book should be displayed in a nice format.

(3) Checkin book: should prompt the user for the book title:

Book Title:

After reading the book title, this option should verify that the book exists and that it is checked out. If so, then the status should be changed in the database, otherwise an error message should be generated.

(4) Checkout book: should prompt the user for the book title and borrower's
name:

Book Title:
Borrower:

After reading the book title and name, this option should verify that the book exists and that it is checked in. If so, the status should be changed in the database, otherwise an error message should be generated. The system date should be used to update the checkout date.

(5) Delete book: should prompt the user for the book title:

Book Title:

After reading the book title, this option should verify that the book exists and that it is not checked out. If so, then the book entry should be deleted in the database, otherwise an error message should be generated.

Each of the sub-options in the Report sub-menu should interact with the user as follows:

(1) Sort by Author: should print a well formatted listing sorted by authors' names of all the books in the database.
(2) Sort by Title: same as (a) but sorting is on title.

(3) Display all checked-out books: should print a well formatting listing of books that are in out status, in ascending order of their check-out dates.
My first question pertains to the adding a book section, I'm unsure which command or conditional statement I need to use to test to see if a book is already in the text file or not.

2. Relevant commands, code, scripts, algorithms:
select and case commands for building menus in bash
some type of sort utility or either grep/awk for any report submenu coding


3. The attempts at a solution (include all code and scripts):
Code:
echo 'Main Menu:'

PS3="$USER, What would you like to do?:  "
echo
status="out"

select reply in "Edit Submenu" "Report Submenu" "Quit"; do

        case $reply in
                "Edit Submenu")
                        echo 'Edit Submenu: '
                        echo
                        select subchoice in "Add a book" "Display a book" "Checkin book" "Checkout book" "Delete a book" "Return to Main Menu"; do
                                case $subchoice in
                                        "Add a book")
                                                printf 'Book Title: '
                                                read title
                                                echo -n  $title > .books
                                                printf 'Author: '
                                                read author
                                                echo -n  $author >> .books
                                                echo $status >> .books
                                ;;
                                        "Display a book")
                                                printf 'Book Title: '
                                                read title
                                ;;
                                        "Checkin book")
                                                printf 'Book Title: '
                                                read title
                                ;;
                                        "Checkout book")
                                                printf 'Book Title: '
                                                read title
                                                echo 'Borrower: '
                                                read borrower
                                ;;   
                                         "Delete a book")
                                                printf 'Book Title: '
                                                read title
                                ;;
                                        "Return to Main Menu")
                                                echo 'return'
                                ;;
                                esac
                                break
                                done
        ;;
                "Report Submenu")
                        echo 'Report Submenu'
                        echo
                        
                        select reportchoice in "Sort by Author" "Sort by Title" "Display all checked-out books" "Return to Main Menu"; do

                                case $reportchoice in
                                        "Sort by Author")
                                                
                                ;;
                                        "Sort by Title")
                                                
                                ;;
                                        "Display all checked-out books")
                                                
                                ;;
                                        "Return to Main Menu")
                                                
                                ;;
                                esac
                                break
                                done
        ;;
                "Quit")
                        echo "Goodbye"
        ;;
        esac

        break
        done

exit


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Georgia State University
Atlanta, Ga
United States
Irina Astrovskaya
CSC 3320


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to select text and apply it to a selected file in bash

In the bash below I am asking the user for a panel and reading that into bed. Then asking the user for a file and reading that into file1.Is the grep in bold the correct way to apply the selected panel to the file? I am getting a syntax error. Thank you :) ... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Alter Fixed Width File

Thank u so much .Its working fine as expected. ---------- Post updated at 03:41 PM ---------- Previous update was at 01:46 PM ---------- I need one more help. I have another file(fixed length) that will get negative value (ex:-00000000003000) in postion (98 - 112) then i have to... (6 Replies)
Discussion started by: vinus
6 Replies

3. Shell Programming and Scripting

Bash shell: Replace a text block by another

Hello, I'm an starter in Bash scripting. I would like to write a script in Bash shell that replaces a specific text block (a function) by another text block in a file: for example in my file --> $HOME/myFile.js replacing following function between other functions in the file: function ABC()... (6 Replies)
Discussion started by: om1559
6 Replies

4. Shell Programming and Scripting

Bash shell script that inserts a text data file into an HTML table

hi , i need to create a bash shell script that insert a text data file into an html made table, this table output has to mailed.I am new to shell scripting and have a very minimum idea of shell scripting. please help. (9 Replies)
Discussion started by: intern123
9 Replies

5. UNIX for Dummies Questions & Answers

alter data in a file

Hi , I have data in file like below. status ----------- ------ 2287 C 1502 E 19 can anyone pls help me how can i get it modified as below status 2287|C|1502 E|19 can someone pls help. Thanks. (2 Replies)
Discussion started by: gaddamja
2 Replies

6. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

7. Shell Programming and Scripting

shell script to alter grub menu.lst

Hi folks, I have a dual-boot Ubuntu/Windows machine and I wanted to create a script to change the menu.lst file so it will change the default boot partition (this is so I can reload the machine remotely and allow it to boot to the Windows partition). Today I have to sudo cp a template file I... (1 Reply)
Discussion started by: ppucci
1 Replies

8. Solaris

Alter zip file without unzipping

I have some zip files. Every file has a "folder/xml file" inside it. Is there any way to change these zip files directly without unzipping them. I want to convert these zip files to "/xml file" (want to move the xml file/s one root up by removing the folder inside it.) Ex: -bash-3.00$ for file... (1 Reply)
Discussion started by: _prasad
1 Replies

9. Shell Programming and Scripting

File Alter Problem--need help

i have 3 files a.txt , b.txt and c.txt each files have keyfields and some column fields e.g. a.txt keyfield1 keyfield2 keyfield3 col1 col2 col3 1 2 3 44 55 66 4 5 6 92 48 33 .....................etc.................. b.txt keyfield1... (2 Replies)
Discussion started by: manas_ranjan
2 Replies

10. Shell Programming and Scripting

Alter Table Shell Script

I want to add some columns to a existing tables through a shell script. Please help. (2 Replies)
Discussion started by: ankitgupta
2 Replies
Login or Register to Ask a Question